Skip to content

bitcoind: add chainwork and size_on_disk to blockchain responses#6

Open
echennells wants to merge 1 commit into
bitcoind-bool-verbosityfrom
bitcoind-chainwork
Open

bitcoind: add chainwork and size_on_disk to blockchain responses#6
echennells wants to merge 1 commit into
bitcoind-bool-verbosityfrom
bitcoind-chainwork

Conversation

@echennells

@echennells echennells commented Jun 13, 2026

Copy link
Copy Markdown
Owner

Adds chainwork to getblockchaininfo, getblockheader, and getblock (verbose), and size_on_disk to getblockchaininfo, for the new bitcoind JSON-RPC interface (libbitcoin#795). Stacked on the bool-verbosity PR.

bitcoind always includes these fields and typed clients (rust-bitcoincore-rpc, corepc) declare them required, so omitting them is a hard deserialization failure, not missing data — ord's startup get_blockchain_info() fails against bs and it can't connect at all, even though it never reads chainwork. to_chain_work() computes cumulative work via query.get_chain_state(...), encoded as bitcoind does (32-byte big-endian hex); size_on_disk reports query.archive_size().

The store keeps only per-header bits, so chainwork is summed from genesis (~3.2s at the testnet3 tip). The second commit adds a single-entry cache — work per hash is immutable, so no invalidation — which brings repeated tip queries to ~15ms. The durable fix, persisting cumulative work per header, is a store-schema decision left out of this PR.

Note for review: libbitcoin#795 omits chainwork deliberately, pointing callers to getchainwork; this reinstates it because typed clients require it on these responses and never call getchainwork.

Testing. Unit tests pin known chainwork constants on the ten-block test store; verified live on testnet3 (genesis and tip exact). Full suite green.

chainwork is required by typed clients (rust-bitcoincore-rpc, corepc)
on getblockchaininfo and getblockheader; size_on_disk on
getblockchaininfo. Derived from chain_state cumulative work and cached
by block hash (immutable) to bound the per-call genesis-span cost.
@echennells echennells force-pushed the bitcoind-bool-verbosity branch from 07b441c to 7a2ec96 Compare June 28, 2026 01:11
@echennells echennells force-pushed the bitcoind-chainwork branch from 78827ce to ee2e710 Compare June 28, 2026 01:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant